package com.ruoyi.process.pipemaintainence2.controller;

import java.util.List;
import java.util.Map;

import com.ruoyi.framework.util.ShiroUtils;
import com.ruoyi.process.pipemaintainence.service.BpmnCopyProcessService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.process.pipemaintainence2.domain.TBpmnCopyProcess;
import com.ruoyi.process.pipemaintainence2.service.ITBpmnCopyProcessService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 抄送流程Controller
 *
 * @author Xianlu Tech
 * @date 2019-12-05
 */
@Controller
@RequestMapping("/process/copy")
public class TBpmnCopyProcessController extends BaseController {

    @Autowired
    protected BpmnCopyProcessService processService;

    private String prefix = "/process/pipeMaintainence2/copy";

    @Autowired
    private ITBpmnCopyProcessService tBpmnCopyProcessService;

    @RequiresPermissions("process:copy:view")
    @GetMapping()
    public String process() {
        return prefix + "/copy";
    }

    //抄送给我的
    @RequiresPermissions("process:copy:copyToMeView")
    @GetMapping("/copyToMe")
    public String copyToMeItem() {
        return prefix + "/copyToMe";
    }

    /**
     * 查询抄送流程列表
     */
    @RequiresPermissions("process:copy:list")
    @PostMapping("/list2")
    @ResponseBody
    public TableDataInfo list(TBpmnCopyProcess tBpmnCopyProcess) {
        startPage();
        List<TBpmnCopyProcess> list = tBpmnCopyProcessService.selectTBpmnCopyProcessList(tBpmnCopyProcess);
        return getDataTable(list);
    }

    /**
     * 导出抄送流程列表
     */
    @RequiresPermissions("process:copy:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TBpmnCopyProcess tBpmnCopyProcess) {
        List<TBpmnCopyProcess> list = tBpmnCopyProcessService.selectTBpmnCopyProcessList(tBpmnCopyProcess);
        ExcelUtil<TBpmnCopyProcess> util = new ExcelUtil<TBpmnCopyProcess>(TBpmnCopyProcess.class);
        return util.exportExcel(list, "process");
    }

    /**
     * 新增抄送流程
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存抄送流程
     */
    @RequiresPermissions("process:copy:add")
    @Log(title = "抄送流程", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TBpmnCopyProcess tBpmnCopyProcess) {
        return toAjax(tBpmnCopyProcessService.insertTBpmnCopyProcess(tBpmnCopyProcess));
    }

    /**
     * 修改抄送流程
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap) {
        TBpmnCopyProcess tBpmnCopyProcess = tBpmnCopyProcessService.selectTBpmnCopyProcessById(id);
        mmap.put("tBpmnCopyProcess", tBpmnCopyProcess);
        return prefix + "/edit";
    }

    /**
     * 修改保存抄送流程
     */
    @RequiresPermissions("process:copy:edit")
    @Log(title = "抄送流程", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TBpmnCopyProcess tBpmnCopyProcess) {
        return toAjax(tBpmnCopyProcessService.updateTBpmnCopyProcess(tBpmnCopyProcess));
    }

    /**
     * 删除抄送流程
     */
    @RequiresPermissions("process:copy:remove")
    @Log(title = "抄送流程", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(tBpmnCopyProcessService.deleteTBpmnCopyProcessByIds(ids));
    }


    /**
     * 查询抄送给我的流程
     */
    @RequiresPermissions("process:copy:copyView")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo copyToMe() {
        List<Map<String, Object>> copyProcessList=tBpmnCopyProcessService.copyToMe();
        return getDataTable(copyProcessList);
    }



}
